//
// Created by 11510 on 2024/6/23.
//

#include "QueryResult.h"
#include <iostream>
#include <string>
using std::string;
using std::ostream;
using std::endl;


string make_plural(size_t ctr, const string& word, const string & ending){
    return (ctr > 1) ? word + ending : word;
}

ostream &operator<<(ostream &os, const QueryResult & queryResult) {

    os << queryResult.sought << " occurs " << queryResult.lines->size() << " "
       << make_plural(queryResult.lines->size(), "time", "s") << endl;

    for (auto num: *queryResult.lines) {
        os << "\t(line " << num + 1 << ") "
           << *(queryResult.file->begin() + num) << endl;
    }
    return os;
}


